<?php
require_once "Sp.php";
// use SimplePhp\Database\DataSourceConstraint;
// use SimplePhp\Database\JoinType;
// use SimplePhp\Database\FieldConstraint;
// use SimplePhp\System\SpClass;
// use SimplePhp\Map\MapNote;
// use SimplePhp\Database\MysqlConstraintBuild;
// use SimplePhp\Database\DbUnit;
// use SimplePhp\Map\NodeReflectionClass;
// use SimplePhp\Map\Table;
use SimplePhp\Database\Model;
use SimplePhp\System as system;
use SimplePhp\Test as test;

/**
 * 初始化系统必要参数
 * 设置Controller的位置
 */
$Context = system\Context::getInstanct();
$rootpath = ROOT_PATH . DIRECTORY_SEPARATOR . "Controller";
// echo $rootpath;
$Context->setControllerPath($rootpath);

var_dump($Context->getConfig());

//手动添加自动载入队列
// \SimplePhp\System\Autoload::registerAutoload("makedown",function($class){
// 	require_once("/var/www/html/test/makedown/".$class.".php");
// });

// \System\Autoload::unregisterAutoload("makedown");

// (new FuckTest())->fuck();

/**
 * 注解获取的测试方法
 */
// $Reflection=SpClass::getClass("DbUnit","",false);
// $map=new MapNote();
// var_dump($map->resolve($Reflection));
// var_dump($Reflection);

/**
 * sql构建的测试
 */
// $DbUnit=new DbUnit();

// $NodeReflectionClass =new NodeReflectionClass($DbUnit);
// $Node=$NodeReflectionClass->resolve(new Table());
// var_dump($Node);

/**
 * model测试
 */
// $video_cat = new test\video_cat(['id', 'name']); //===>可以输入要的列

// $video_cat=new test\video_cat("count(name)");   //==>可以输入字符串替换列字符串
// $video_cat=new test\video_cat(false);   //==>可以设置不选中任何列
// $video_cat=new test\video_cat(["id"=>2,"name"=>"ying"]);   //==>还可以直接给列赋值(在insert中有效)
// $video_cat=new test\video_cat();   //==>默认初始化为选择所有列

// $video_cat->join(new test\video_course(['course_id', 'name', 'video_path']), "$.id=#.cat_id");
// $video_cat->fieldTemp(['name' => "count(?)"]);
// $video_cat->where(["id", 23]);
// $model = new Model();
// $data = $model->select($video_cat);
// var_dump($data);
// var_dump($video_cat->select());

// $video_user=new test\video_user(false);
// $video_user = new test\video_user();

$video_user = new test\video_user(['username']);
// 设置列的替换方式
$video_user->fieldTemp(['username' => "SUBSTRING(? FROM 2)"]);
$video_user->field("count(case when username='ying' then username end) as 'ying'");
// $video_user->field("*");
// $Construct=new SimplePhp\Database\DbUnit();
// $Construct->

//手动设置数据源
// $video_user->datasourseJoinType(database\JoinType::left_join);
// $video_user->datasourse("video_user_course",'c',"c.uid=video_user.uid");
// $video_user->where(['uid',"(1,2,4)",database\Where::not_in,database\WhereCon::and_]);
// $video_user->datasourse("(select * from video_user_course)",'a',"c.uid=video_user.uid");
/**
 * 这里第二个参数是指定限制的表名
 */
// $video_user->where(['uid',2,database\Where::eq_,database\WhereCon::or_]);
// $video_user->where(['username',"asdf",database\Where::eq_]);
//批量设置where
// $video_user->wheres(
// 	[
// 		['uid',	2,	database\Where::eq_,	    database\WhereCon::or_],
// 		["username",	"asdf",	"=",	" or "]
// 	]);
// $video_user->wheres(
// 	[
// 		['uid',	2],
// 		["username",	"asdf",	"=",	" or "]
// 	]);
// $video_user->where(["uid", 3, db\Where::eq_, db\WhereCon::or_]);
// $video_user->where(["uid", 1, db\Where::eq_, db\WhereCon::or_]);
// $video_user->where(["username", "13434534"]);
// $model=new Model();
// var_dump($model->select($video_user));
var_dump($video_user->select());

//数据库插入测试
//之后要考虑一对多和多对多的插入
// $model = new Model();
// $data = new test\video_user(["username" => "test_insert", "password" => "many_test"]);
// $data2 = new test\video_user();
// $data2->username = "insert_test2";
// $data2->password = "insert_test2";
// $all = [$data, $data2];
// var_dump($model->insert($all));

// $ExecController=new dispatcher\ExecController();
// $ExecController->exec();

/**
 * Ioc测试
 */

// $injectTest=new test\InjectTest();
// var_dump($injectTest->DbHelp);
// $underlineParseRequest=new dispatcher\PointParseRequest();
// var_dump($underlineParseRequest);
// $testData=["user.name"=>"chen","c"=>"test","user.password"=>"1234","model.uid"=>23,"model.kk"=>234];
// $result=$underlineParseRequest->parse($testData);
// var_dump($result);

/*$oXMLout = new XMLWriter();
$oXMLout->openMemory();
$oXMLout->startElement("item");
$oXMLout->writeElement("quantity", 8);
$oXMLout->writeElement("price_per_quantity", 110);
$oXMLout->endElement();
$oXMLout->text("<?php echo fuck?>");
 */

// $i=2;
// $k=5;
// $number=$i | $k;
// printf("二进制:%1$04b \n",$number) ;

// $format = '(%1$2d = %1$04b) = (%2$2d = %2$04b)'
//         . ' %3$s (%4$2d = %4$04b)' . "\n";

// echo <<<EOH
//  ---------     ---------  -- ---------
//  result        value      op test
//  ---------     ---------  -- ---------
// EOH;

// /*
//  * Here are the examples.
//  */

// $values = array(0, 1, 2, 4, 8);
// $test = 1 + 4;

// echo "\n Bitwise AND \n";
// foreach ($values as $value) {
//     $result = $value & $test;
//     printf($format, $result, $value, '&', $test);
// }

// echo "\n Bitwise Inclusive OR \n";
// foreach ($values as $value) {
//     $result = $value | $test;
//     printf($format, $result, $value, '|', $test);
// }

// echo "\n Bitwise Exclusive OR (XOR) \n";
// foreach ($values as $value) {
//     $result = $value ^ $test;
//     printf($format, $result, $value, '^', $test);
// }